package com.swxc.smartorder.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.swxc.smartorder.ui.fragment.PreviewFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Author   Administrator
 * Date     2018/4/13
 * Desc     eg
 *
 * @author Administrator
 */
public class PreviewPagerAdapter extends FragmentPagerAdapter {

    private ArrayList<String> mItems = new ArrayList<>();
    private OnPrimaryItemSetListener mListener;

    public PreviewPagerAdapter(FragmentManager manager, OnPrimaryItemSetListener listener) {
        super(manager);
        mListener = listener;
    }

    @Override
    public Fragment getItem(int position) {
        return PreviewFragment.newInstance(mItems.get(position));
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        if (mListener != null) {
            mListener.onPrimaryItemSet(position);
        }
    }

    public String getMediaItem(int position) {
        return mItems.get(position);
    }

    public void addAll(List<String> items) {
        mItems.addAll(items);
    }

    public interface OnPrimaryItemSetListener {

        void onPrimaryItemSet(int position);
    }

}
